package club.baimahu.pencil.servlet;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SimpleHandlerFactory {

    static Map<Method,Object> methodObject = new ConcurrentHashMap<>();

    public static SimpleHandler getSimpleHandler(Method method){
        try {
            if(methodObject.containsKey(method)){
                return new SimpleHandler(method,methodObject.get(method));
            }else{
                Object object = method.getDeclaringClass().newInstance();
                methodObject.put(method,object);
                return new SimpleHandler(method,object);
            }
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }
}
